In [2]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
In [54]:
def sigmoid(z):
return 1 / (1 + np.exp(-z))
z = np.linspace(-10, 10, 1000)
a = sigmoid(z)
In [55]:
plt.plot(z, a)
plt.xlabel("Z")
plt.ylabel("g(z)")
plt.title("Sigmoid")
plt.grid(True)
In [56]:
dz = a*(1-a)
plt.plot(z, dz)
plt.xlabel("Z")
plt.ylabel("g'(z)")
plt.title("Derivative of Sigmoid function")
plt.grid(True)
In [57]:
def tanh(z):
return (np.exp(z) - np.exp(-z)) / (np.exp(z) + np.exp(-z))
z = np.linspace(-10, 10, 1000)
a = tanh(z)
In [58]:
plt.plot(z, a)
plt.xlabel("Z")
plt.ylabel("g(z)")
plt.title("tanh")
plt.grid(True)
In [59]:
dz = 1 - (a ** 2)
plt.plot(z, dz)
plt.xlabel("Z")
plt.ylabel("g'(z)")
plt.title("Derivative of tanh")
plt.grid(True)
In [60]:
def relu(z):
return np.maximum(0, z)
z = np.linspace(-10, 10, 1000)
a = relu(z)
In [61]:
plt.plot(z, a)
plt.xlabel("Z")
plt.ylabel("g(z)")
plt.title("relu")
plt.grid(True)
In [62]:
dz = np.where(z <=0, 0, 1)
plt.plot(z, dz)
plt.xlabel("Z")
plt.ylabel("g'(z)")
plt.title("Derivative of relu")
plt.grid(True)
In [65]:
def weak_relu(z):
return np.maximum(0.01 * z, z)
z = np.linspace(-10, 10, 1000)
a = weak_relu(z)
In [66]:
plt.plot(z, a)
plt.xlabel("Z")
plt.ylabel("g(z)")
plt.title("Weak relu")
plt.grid(True)
In [ ]:
In [ ]: